package com.fzf.org.controller;

import com.fzf.org.dto.req.blog.BlogReqDTO;
import com.fzf.org.dto.resp.blog.BlogDTO;
import com.fzf.org.page.PageRequest;
import com.fzf.org.page.PageResponse;
import com.fzf.org.result.Result;
import com.fzf.org.result.Results;
import com.fzf.org.service.BlogsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/blog/blog")
@RestController
@RequiredArgsConstructor
public class BlogsController {

    private final BlogsService blogsService;

    /**
     * 分页获取用户的blog
     * @param pageRequest 分页参数
     * @return
     */
    @GetMapping("/blogList")
    Result<PageResponse<BlogDTO>> listUsersBlog(PageRequest pageRequest) {
        return Results.success(blogsService.listUsersBlogs(pageRequest));
    }

    /**
     * 根据id获取用户的Blog
     * @param blogID blog实体id
     * @return
     */
    @GetMapping("/blogDetail")
    Result<BlogDTO> showBlogDetail(@RequestParam("blogID") Long blogID) {
        return Results.success(blogsService.showBlogDetail(blogID));
    }

    /**
     * 修改Blog内容，只会修改content、title
     * @param blogReqDTO 完整的BlogDTO实体
     * @return
     */
    @PostMapping("/update")
    Result<Void> updateBlog(@RequestBody BlogReqDTO blogReqDTO) {
        blogsService.updateBlog(blogReqDTO);
        return Results.success();
    }

    /**
     * 根据id删除用户的Blog
     * @param blogID blog实体id
     * @return
     */
    @PostMapping("/delBlog")
    Result<Void> delBlog(@RequestParam("blogID") Long blogID) {
        blogsService.delBlog(blogID);
        return Results.success();
    }

}
